<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: checkout_confirmation.php 158 2013-09-22 07:53:09Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 158 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:53:09 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');

$smarty = new Smarty;

require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');

require_once (DIR_FS_INC.'inc.calculate_tax.php');
require_once (DIR_FS_INC.'inc.check_stock.php');
require_once (DIR_FS_INC.'inc.display_tax_value.php');

if(!isset($_SESSION['customer_id']))
	redirect(href_link(FILENAME_LOGIN, '', 'SSL'));

if($_SESSION['cart']->count_contents() < 1)
	redirect(href_link(FILENAME_SHOPPING_CART));

if(isset($_SESSION['cart']->cartID) && isset ($_SESSION['cartID'])) {
	if ($_SESSION['cart']->cartID != $_SESSION['cartID'])
		redirect(href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}

if(!isset($_SESSION['shipping']))
	redirect(href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

if(isset($_SESSION['tmp_oID'])) 
	unset($_SESSION['tmp_oID']);

if(isset ($_POST['payment']))
	$_SESSION['payment'] = $_POST['payment'];

if($_POST['comments_added'] != '')
	$_SESSION['comments'] = $_POST['comments'];

if(isset($_POST['cot_gv']))
	$_SESSION['cot_gv'] = true;

unset($_SESSION['error_message']);

if(!isset($_SESSION['all_checkout_checks_ok'])) {
	if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
		if ($_REQUEST['conditions'] == false) {
			$error = str_replace('\n', '<br />', ERROR_CONDITIONS_NOT_ACCEPTED);
			$_SESSION['error_message'] = urlencode($error);
			redirect(href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
		}
	}

	if (DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
		if ($_REQUEST['datenschutz'] == false){
			$error = str_replace( '\n', '<br />', ERROR_DATENSCHUTZ_NOT_ACCEPTED );
			$_SESSION['error_message'] = urlencode($error);
			redirect(href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
		}
	}

	if (DISPLAY_WIDERRUFSRECHT_ON_CHECKOUT == 'true') {
		if ($_POST['widerrufsrecht'] == false){
			$error = str_replace( '\n', '<br />', ERROR_WIDERRUFSRECHT_NOT_ACCEPTED );
			$_SESSION['error_message'] = urlencode($error);
			redirect(href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
		}
    }
    $_SESSION['all_checkout_checks_ok'] = 'true';
}

checkout_site('confirm');

require (DIR_WS_CLASSES.'class.payment.php');
if (isset ($_SESSION['credit_covers']))
	$_SESSION['payment'] = 'no_payment'; // GV Code Start/End ICW added for CREDIT CLASS
$payment_modules = new payment($_SESSION['payment']);

require (DIR_WS_CLASSES.'class.order_total.php');
require (DIR_WS_CLASSES.'class.order.php');
$order = new order();

$payment_modules->update_status();

$order_total_modules = new order_total();
$order_total_modules->collect_posts();
$order_total_modules->pre_confirmation_check();

if ((is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && (!is_object($$_SESSION['payment'])) && (!isset ($_SESSION['credit_covers']))) || (is_object($$_SESSION['payment']) && ($$_SESSION['payment']->enabled == false))) {
	$_SESSION['error_message'] = urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED);
	redirect(href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

if (is_array($payment_modules->modules))
	$payment_modules->pre_confirmation_check();

require (DIR_WS_CLASSES.'class.shipping.php');
$shipping_modules = new shipping($_SESSION['shipping']);

$any_out_of_stock = false;
if (STOCK_CHECK == 'true') {
	for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
		if (check_stock($order->products[$i]['id'], $order->products[$i]['qty']))
			$any_out_of_stock = true;
	}
	if ((STOCK_ALLOW_CHECKOUT != 'true') && ($any_out_of_stock == true))
		redirect(href_link(FILENAME_SHOPPING_CART));
}

$breadcrumb->add(NAVBAR_TITLE_1_CHECKOUT_CONFIRMATION, href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2_CHECKOUT_CONFIRMATION);

require(DIR_WS_INCLUDES.'header.php');
if (isset($_GET['payment_error']) && is_object(${ $_GET['payment_error'] }) && ($error = ${$_GET['payment_error']}->get_error())) {
   $smarty->assign('error', htmlspecialchars($error['error']));
}

if (SHOW_IP_LOG == 'true') {
	$smarty->assign('IP_LOG', 'true');
	if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
		$customers_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	} else {
		$customers_ip = $_SERVER["REMOTE_ADDR"];
	}
	$smarty->assign('CUSTOMERS_IP', $customers_ip);
}
$smarty->assign('DELIVERY_LABEL', address_format($order->delivery['format_id'], $order->delivery, 1, ' ', '<br />'));
if ($_SESSION['credit_covers'] != '1') {
	$smarty->assign('BILLING_LABEL', address_format($order->billing['format_id'], $order->billing, 1, ' ', '<br />'));
}
$smarty->assign('PRODUCTS_EDIT', href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
$smarty->assign('SHIPPING_ADDRESS_EDIT', href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL'));
$smarty->assign('BILLING_ADDRESS_EDIT', href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL'));

if ($_SESSION['sendto'] != false) {

	if ($order->info['shipping_method']) {
		$smarty->assign('SHIPPING_METHOD', $order->info['shipping_method']);
		$smarty->assign('SHIPPING_EDIT', href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
	}
}

require(DIR_WS_MODULES.'checkout_confirmation_details.php');

if ($order->info['payment_method'] != 'no_payment' && $order->info['payment_method'] != '') {
	include (DIR_WS_LANGUAGES.'/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php');
	$smarty->assign('PAYMENT_METHOD', constant(MODULE_PAYMENT_.strtoupper($order->info['payment_method'])._TEXT_TITLE));
	if (isset($_GET['payment_error']) && is_object(${$_GET['payment_error']}) && ($error = ${$_GET['payment_error']}->get_error()))
		$smarty->assign('error', $error['title'].'<br />'.htmlspecialchars($error['error']));
}
$smarty->assign('PAYMENT_EDIT', href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

$total_block = '';
if (MODULE_ORDER_TOTAL_INSTALLED) {
        $aryNNTotal = $order_total_modules->process();
        if(count($aryNNTotal)!=0) {
          foreach($aryNNTotal as $nnkey => $nnval) {
            if($nnval['code']=='ot_total') {
                $_SESSION['nn_total'] = strtolower($nnval['text']);
                $_SESSION['nn_total'] = str_replace('<b>', '', $_SESSION['nn_total']);
                $_SESSION['nn_total'] = str_replace('</b>', '', $_SESSION['nn_total']);
                $_SESSION['nn_total'] = trim($_SESSION['nn_total']);
                list($_SESSION['nn_total'], $extra) = explode(' ', trim($_SESSION['nn_total']));
            }
          }
        }
	$total_block .= $order_total_modules->output();
}
$total_block .= '';
$smarty->assign('TOTAL_BLOCK', $total_block);

if (is_array($payment_modules->modules)) {
	if ($confirmation = $payment_modules->confirmation()) {
		$payment_info = $confirmation['title'];
		for ($i = 0, $n = sizeof($confirmation['fields']); $i < $n; $i++)
			$payment_info .= '<div>'.$confirmation['fields'][$i]['title'].stripslashes($confirmation['fields'][$i]['field']).'</div>';

		$smarty->assign('PAYMENT_INFORMATION', $payment_info);
	}
}

if (not_null($order->info['comments']))
	$smarty->assign('ORDER_COMMENTS', nl2br(htmlspecialchars($order->info['comments'])).draw_hidden_field('comments', $order->info['comments']));

if (isset ($$_SESSION['payment']->form_action_url) && !$$_SESSION['payment']->tmpOrders)
	$form_action_url = $$_SESSION['payment']->form_action_url;
else
	$form_action_url = href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');

$smarty->assign('CHECKOUT_FORM', draw_form('checkout_confirmation', $form_action_url, 'post'));
$payment_button = '';
if (is_array($payment_modules->modules))
	$payment_button .= $payment_modules->process_button();

$smarty->assign('MODULE_BUTTONS', $payment_button);
$smarty->assign('CHECKOUT_BUTTON', image_submit('button_confirm_order.gif', IMAGE_BUTTON_CONFIRM_ORDER).'</form>'."\n");
$smarty->assign('BUTTON_EDIT', image_button('button_edit.gif', 'bearbeiten'));

if (DISPLAY_REVOCATION_ON_CHECKOUT == 'true') {

	if (GROUP_CHECK == 'true')
		$group_check = "and group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";

	$shop_content_data = $db->db_query("SELECT
											content_title,
											content_heading,
											content_text,
											content_file
										FROM 
											".TABLE_CONTENT_MANAGER."
										WHERE 
											content_group='".REVOCATION_ID."' ".$group_check."
										AND 
											languages_id='".$_SESSION['languages_id']."'");

	if ($shop_content_data->fields['content_file'] != '') {
		ob_start();
		if (strpos($shop_content_data->fields['content_file'], '.txt'))
			echo '<pre>';
		include (DIR_FS_CATALOG.'media/content/'.$shop_content_data->fields['content_file']);
		if (strpos($shop_content_data->fields['content_file'], '.txt'))
			echo '</pre>';
		$revocation = ob_get_contents();
		ob_end_clean();
	} else {
		$revocation = $shop_content_data->fields['content_text'];
	}

	$smarty->assign('REVOCATION', $revocation);
	$smarty->assign('REVOCATION_TITLE', $shop_content_data->fields['content_heading']);
	$smarty->assign('REVOCATION_LINK', $main->getContentLink(REVOCATION_ID, MORE_INFO));

	$shop_content_data = $db->db_query("SELECT
											content_title,
											content_heading,
											content_text,
											content_file
										FROM 
											".TABLE_CONTENT_MANAGER."
										WHERE 
											content_group='3' ".$group_check."
										AND 
											languages_id = '".$_SESSION['languages_id']."'");

	$smarty->assign('AGB_TITLE', $shop_content_data->fields['content_heading']);
	$smarty->assign('AGB_LINK', $main->getContentLink(3, MORE_INFO));
}

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('PAYMENT_BLOCK', $payment_block);
$smarty->caching = false;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/checkout_confirmation.html');

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if (!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>